package lab1;
/*  $Id: mStack.java
 *  
 *  Copyright 2011, The Johns Hopkins University Whiting School of Engineering
 *  All rights reserved.
 *  This material may be used, modified and reproduced by faculty,
 *  staff, and students of The Johns Hopkins University for instruction, 
 *  evaluation, and grading purposes.  For any other permission, please 
 *  contact The Johns Hopkins University Whiting School of Engineering.
 */
import java.io.IOException;
/**
 *  Lab1 1: Stack 
 *  @date       30JUNE2012
 *  @author     Michael W. Mathes
 *  The author would like to cite the stack example in project0 provided by the 
 *  class as basis for this iteration.
 * 
 */
public class mStack {
    char[] items;
    int   maxItems;
    int   top;

    /**
     *  Creates a new stack of char's.
     *  @param height The maximum number of elements that the stack can hold.
     */
    public mStack(int height) {
        maxItems = height + 1;
        items = new char[maxItems];
        top   = 0;
    }
    
    /**
     *  See if the stack is empty.
     *  @return <code>true</code> if the stack is empty, otherwise </code>
     *      false</code>
     */
     public boolean isEmpty() {
        if (top > 0)
            return false;
        else
            return true;
     }
     
    /**
     *  See if the stack is full.
     *  @return <code>true</code> if the stack is full, otherwise </code>
     *      false</code>
     */
    public boolean isFull() {
        if (top == maxItems - 1)
            return true;
        else
            return false;
    }
    
    /**
     *  Pops the top item off the stack and moves the top to the next item down.
     *  @return The top item from the stack.
     */
    public char pop() throws EmptyStackException {
        char ToReturn;
        
        // pop an empty stack should error
        if (top == 0){
          throw new EmptyStackException();
        }
        
        ToReturn = items[top];
        top--;
        
        return ToReturn;
    }
    
    /**
     *  Pushes an integer onto the stack.
     *  @param number An integer to push onto the top of the stack.
     */
    public void push(char cha) {
        top++;
        items[top] = cha;
    }
    
    
    public Character peek() {
        Character ToReturn;
        ToReturn = items[top];
        return ToReturn;
    }
    

    // Creating an empty stack exception
    public class EmptyStackException extends IOException {
    }
    
    
}
